package com.carryon.modules.sj.execute;

import java.lang.reflect.Method;

import com.carryon.modules.sj.Execute;
import com.carryon.modules.sj.SJ;
import com.carryon.modules.sj.exception.InternalServerException;

/**
 * @author Helin
 * @mail hl_0074@sina.com
 * @date 2011-9-28
 * 
 */
public class SJExecute implements Execute {

	private String method;

	public SJExecute(String method) {

		this.method = method;
	}

	@Override
	public void execute(SJ sj) throws Exception {

		Method invoke = null;
		try {
			invoke = sj.getClass().getMethod(this.method);
		} catch (Exception e) {
			throw new InternalServerException("method not found:"+sj.getClass().getCanonicalName()+"."+this.method+"()", e);
		}

		try {
			invoke.setAccessible(true);
			invoke.invoke(sj);
		} catch (Exception e) {
			throw new Exception(e.getCause().getMessage(),e);
		}
	}

}
